package Filter;

import Entity.Teacher;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/*
拦截器 拦截教师后台登陆 无教师Session则跳转到404页面
 */
@WebFilter(value = "/jsp/admin/teacher/*")
public class TeacherFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {

        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) resp;

        Teacher teacher = (Teacher) request.getSession().getAttribute("teacher");


        if (teacher == null){
            // System.out.println("拦截不能通过");
            response.sendRedirect("../../../404.jsp");
            return;
        }
        //System.out.println("拦截放行");
        chain.doFilter(req, resp);
    }

    public void init(FilterConfig config) throws ServletException {

    }

}
